﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_AdminSurrogateList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestLoginPage = "BalanceCenter/AdminSurrogateList.aspx";

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        DataTable dt = DAL.Views.V_Users.Select("", "isSurrogate = 1", "[ID]");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }

    protected void g_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        if (e.CommandName == "btnAeecpt")
        {
            ShoveEL.Database.MSSQL.ExecuteNonQuery("Update T_Users set isSurrogate = 0 where [ID] = " + ShoveEL._Convert.StrToLong(e.Item.Cells[9].Text, -1).ToString());
            ShoveEL.Database.MSSQL.ExecuteNonQuery("Delete from T_TryForSurrogate where [ID] = " + ShoveEL._Convert.StrToLong(e.Item.Cells[9].Text, -1).ToString());

            if (_User.ID == ShoveEL._Convert.StrToLong(e.Item.Cells[9].Text, -1))
            {
                string ReturnDescription = "";

                _User.GetUserInfoByID(ref ReturnDescription);
            }

            try
            {
                BindData();
            }
            catch
            {
                if (gPager.PageIndex > 0)
                {
                    gPager.PageIndex -= 1;

                    BindData();
                }
            }

            ShoveEL._Web.JavaScript.Alert(this, "处理成功。");

            return;
        }
    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void g_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            //
        }
    }
}